﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CoreProcess.FileStorageScan
{
    public class FileStorageScan
    {
        public static IList<ScanExceptionObj> Scan(string dirPath, Action<string> fileAction)
        {
            var scanExceptionList =
                new List<ScanExceptionObj>();
            try
            {
                foreach (var file in Directory.EnumerateFiles(dirPath))
                {
                    ////if (file.Length > 260)
                    ////    continue;
                    //logger.Debug("asdf");
                    //logger.Error("error");

                    //var ff =
                    //    //new FileInfo(@"\\?\ "+file);
                    //    new FileInfo(file);

                    fileAction.Invoke(file);

                    //if (ff.Extension.ToUpper().EndsWith("PDF"))
                    //{
                    //    Console.WriteLine(ff.Name);
                    //}

                }

                foreach (var dir in Directory.EnumerateDirectories(dirPath))
                {
                    Scan(dir, fileAction);
                }
            }
            catch (Exception ex)
            {
                scanExceptionList.Add(new ScanExceptionObj()
                {
                    ScanEx = ex,
                    ScanPath = dirPath
                });
            }

            return scanExceptionList;
        }
    }
}
